/**
 * 获取token值
 */
 exports.getToken = () => {
    return wx.getStorageSync("token");
  }
  
  /**
   * 未登录处理
   */
  exports.showLoginError = () => {
    // 未登录或者token值丢失
    console.log("-----------------------------------------------------");
    console.log("无权限，跳转登录界面");
    wx.reLaunch({
      url: "/loginPack/index",
    });
  }
  
  /**
   * 显示网络错误
   */
  exports.showNetWorkError = (networkType, retryFailedRequest, giveUpFailedRequest) => {
    if (getApp().globalData.isRequestErrorVisible) return;
  
    getApp().globalData.isRequestErrorVisible = true;
  
    var titleString = isDebugStatus
      ? "网络不稳定【" + networkType + "】"
      : "网络不稳定";
    titleString = "网络不稳定【" + networkType + "】";
  
    wx.showModal({
      title: titleString,
      content: "当前网络不稳定，请检查网络或稍后再试",
      cancelText: "稍候再试",
      cancelColor: "#999999",
      confirmText: "重新加载",
      confirmColor: "#FF8F28",
      success(res) {
        if (res.confirm) {
          // 重新发送失败的请求
          retryFailedRequest();
        } else if (res.cancel) {
          // 稍后再试
          giveUpFailedRequest();
        }
      },
      complete() {
        getApp().globalData.isRequestErrorVisible = false;
      },
    });
  }
  
  /**
   * 显示网络错误
   */
  exports.showSytemError = (retryFailedRequest, giveUpFailedRequest) => {
    if (getApp().globalData.isRequestErrorVisible) return;
  
    getApp().globalData.isRequestErrorVisible = true;
  
    var contentString = "当前系统异常，请稍候重新尝试";
    if (isDebugStatus) {
      // 开发模式下的显示处理
  
      contentString = "";
      requestFailList.map((data) => {
        var uuid = data[0];
        var error = data[1].data == undefined ? data[1] : data[1].data;
        var { url } = requestManager.get(uuid);
  
        contentString += "请求地址：" + url;
        contentString +=
          "------------------------错误信息：\n" + JSON.stringify(error) + "\n";
      });
    }
  
    wx.showModal({
      title: "系统异常",
      content: contentString,
      cancelText: "稍候再试",
      cancelColor: "#999999",
      confirmText: "重新加载",
      confirmColor: "#FF8F28",
      success(res) {
        if (res.confirm) {
          // 重新发送失败的请求
          retryFailedRequest();
        } else if (res.cancel) {
          // 稍后再试
          giveUpFailedRequest();
        }
      },
      complete() {
        getApp().globalData.isRequestErrorVisible = false;
      },
    });
  }

  /**
   * 是否应该重新登录
   * @param {*} ressultData 
   */
  exports.shouldReLogin = (res) => {
    return (res.data.code == 389 && res.data.msg == "认证失败") ||
    (res.code == 389 && res.msg == "认证失败") ||
    (res.data.code == 389 && res.data.msg == "认证失败，请重新登陆。")
  }
  
  